package com.example.demo.facility;

import com.example.demo.annotation.FieldAndTypeAnnotation;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Set;

@Component
public class GetBeanFacility {
    @Resource
    private Map<String , BaseFacility> facilityMap;

    public  BaseFacility getBaseFacility(String type) {
        Set<Map.Entry<String, BaseFacility>> entries = facilityMap.entrySet();
        for (Map.Entry<String, BaseFacility> entry : entries) {
            FieldAndTypeAnnotation annotation = entry.getValue().getClass().getAnnotation(FieldAndTypeAnnotation.class);
            if (annotation.value().equals(type)) {
               return entry.getValue();
            }
        }
        return null;
    }
}
